import torch

def evaluate(model, loader, device):
    model.eval()
    correct, total = 0, 0
    with torch.no_grad():
        for x, y in loader:
            x, y = x.to(device), y.to(device)
            out = model(x)
            _, predicted = out.max(1)
            correct += predicted.eq(y).sum().item()
            total += y.size(0)
    return 100. * correct / total

def count_params(model):
    return sum(p.numel() for p in model.parameters() if p.requires_grad)

def count_flops(model, input_size):
    from thop import profile
    dummy_input = torch.randn(input_size).to(next(model.parameters()).device)
    flops, _ = profile(model, inputs=(dummy_input,), verbose=False)
    return flops / 1e6
